package com.bjsxt;
/**Thread 获得线程名的方法*/

//继承Thread类的，直接通过getName()方法获得
class GetName extends Thread{
    @Override
    public void run() {
        System.out.println(this.getName());
    }
}
//实现了Runnable接口，通过Thread.currentThread().getName()
class GetName2 implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}
public class GetNameThread {
    public static void main(String[] args) {
        GetName gn = new GetName();
        gn.start();
        System.out.println("------------");
        Thread t = new Thread(new GetName2());
        t.start();
    }

}
